package org.example.web.controllers;

import lombok.extern.slf4j.Slf4j;
import org.example.annotations.component.Controller;
import org.example.annotations.route.GetMapping;
import org.example.annotations.route.PostMapping;
import org.example.web.services.ITestService;

import java.nio.charset.Charset;


@Slf4j
@Controller
public class IndexController {

    private final ITestService service;

    public IndexController (ITestService service) {
        log.info("IndexController created");
        System.out.println("Default Charset: " + Charset.defaultCharset().displayName());
        System.out.println("Default Locale: " + System.getProperty("user.language"));
        log.info("你好，世界");
        log.info(service.getMessage("index"));
        this.service = service;
    }


    @GetMapping("/index/{msg}")
    public String index(String msg) {
        return "index" + service.getMessage(msg);
    }

    @GetMapping("/index")
    public String index() {
        return "index";
    }

    @PostMapping("/index")
    public String create() {
        return "index" + service.getMessage("create");
    }

    @PostMapping("/index/{id}")
    public String update(String id) {
        return "index" + service.getMessage("update - " + id);
    }
}
